﻿using AutoMapper;
using B.S.Warehouse.Domain;
using B.S.Warehouse.ErrorCord;
using B.S.Warehouse.Write.Api.Application.Command.StockInDetailCommand;
using MediatR;
using SqlSugar;

namespace B.S.Warehouse.Write.Api.Application.Handelr.StockInDetailHandelr
{
    /// <summary>
    /// 入库申请明细表添加
    /// </summary>
    public class AddStockInDetailHandelr : IRequestHandler<AddStockInDetailCommand, ApiResult<object>>
    {
        private readonly ISqlSugarClient db;
        private readonly IMapper mapper;
        public AddStockInDetailHandelr(ISqlSugarClient db, IMapper mapper)
        {
            this.db = db;
            this.mapper = mapper;
        }
        public async Task<ApiResult<object>> Handle(AddStockInDetailCommand request, CancellationToken cancellationToken)
        {
            ApiResult<object> result = new ApiResult<object>();

            result.Code = ApiEnum.添加成功;
            result.MAG = ApiEnum.添加成功.ToString();
            var model = mapper.Map<StockInDetailS>(request);
            model.IsDel = false;
            await db.Insertable(model).ExecuteCommandAsync();

            return await Task.FromResult(result);

        }
    }
}
